<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dettaglio alunno</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" />
<link href="../../css/themes/default.css" rel="stylesheet" type="text/css"/>
<link href="../../css/themes/alphacube.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../js/prototype.js"></script>
<script type="text/javascript" src="../../js/scriptaculous.js"></script>
<script type="text/javascript" src="../../js/page.js"></script>
<script type="text/javascript" src="../../js/window.js"></script>
<script type="text/javascript" src="../../js/window_effects.js"></script>
<script type="text/javascript">
function go(par, id, tipo){
	if(par == 2){
        if(!confirm("Sei sicuro di voler cancellare questo documento?"))
            return false;
    }
	$('_i').value = id;
    $('action').value = par;
    var url = "<?php print $_SESSION['__config__']['root_site'] ?>admin/adm_docs/document_manager.php";
	var req = new Ajax.Request(url,
			  {
			    	method:'post',
			    	parameters: $('doc_form').serialize(true),
			    	onSuccess: function(transport){
			      		var response = transport.responseText || "no response text";
			      		//alert(response);
			      		//return;
			      		var dati = response.split("|");
			      		if(dati[0] == "ko"){
							alert(dati[1]+"\n"+dati[2]);
							return;
			      		}
			      		parent.win.close();
			      		link = "index.php?msg="+par;
						parent.document.location.href = link;
			      		//parent.win.close();
			    	},
			    	onFailure: function(){ alert("Si e' verificato un errore..."); }
			  });
}

function check_privato(control){
	if(control.checked)
		Effect.BlindDown('gpr', { duration: 1.0 });
	else
		Effect.SlideUp('gpr', { duration: 1.0 });
}

var loaded = false;
function loading(time){
	openInfoDialog("Attendere il caricamento del file...", time);
}

</script>
</head>
<body <?php if(isset($msg)) print("onLoad=\"alert('".$msg."'); window.close(); window.opener.document.location.href='".$opener."'\"") ?>>
    <p class="popup_header">Gestione documento</p>
    <form action="dettaglio_documento.php?upd=1" method="post" enctype="multipart/form-data" id="doc_form">
    <div style="margin-right: auto; margin-left: auto; margin-top: 10px; width: 600px">
    	<fieldset style="width: 600px; border: 1px solid; padding-top: 10px; ">
	    <legend style="font-weight: bold; margin-left: 10px">Documento</legend>
	    <table style="margin-right: auto; margin-left: auto; width: 580px">
	        <tr class="popup_row header_row">
	            <td class="popup_title" style="width: 150px;padding-left: 10px">Abstract</td>
	            <td style="width: 430px; " colspan="3">
	            	<input class="form_input" type="text" name="abstract" style="width: 430px" value="<?php if(isset($doc)) print $doc['abstract'] ?>"  />
	            </td>
	        </tr>
	        <tr class="popup_row">
	        	<td class="popup_title" style="width: 150px; padding-left: 10px">Anno scolastico</td>
	            <td style="width: 200px; vertical-align: middle">
	                <select class="form_input" style="width: 165px; " name="anno">
	            <?php
				while($year = $res_anni->fetch_assoc()){
	            ?>
	            		<option <?php if($year['id_anno'] == $doc['anno_scolastico']) print("selected='selected'") ?> value="<?php print $year['id_anno'] ?>"><?php print $year['descrizione'] ?></option>
	            <?php } ?>
	                </select>
	            </td>
	            <td class="popup_title" style="width: 150px; padding-left: 10px; text-align: right">Privato</td>
	            <td style="width: 70px; vertical-align: middle; color: #003366; text-align: right; padding-right: 0px">
	                <input class="form_input" type="checkbox" onclick="check_privato(this)" name="privato" value="1" <?php if($doc['privato'] == 1 ) print("checked='checked'") ?> /> 
	            </td>
	        </tr>
	        <tr class="popup_row">
	            <td class="popup_title" style="width: 150px; padding-left: 10px">File</td>
	            <td style="color: #003366; text-align: right; padding-right: 0px" colspan="3">
	            <?php if(isset($doc)){ ?>
	            	<input class="form_input" type="text" name="fname" class="file" style="width: 430px" value="<?php print $doc['file'] ?>"/>
	            <?php }  else{ ?>
	            	<iframe src="send_file.php" style="border: none; width: 430px;  margin: 0px; height: 25px" frameborder="0" id="aframe"></iframe>
            <?php } ?>
	            </td>
	        </tr>
	        <tr class="popup_row">
	        	<td colspan="4"></td>
	        </tr>
	    </table>
        </fieldset>
        <fieldset style="width: 600px; border: 1px solid; padding-top: 10px; <?php if($doc['privato'] == 1 ) print("display: block"); else print ("display: none") ?>; margin-top: 30px" id="gpr">
	    <legend style="font-weight: bold; margin-left: 10px">Gruppi di accesso</legend>
	    <table style="width: 580px; margin-right: auto; margin-left: auto">
	        <tr class="popup_row header_row">
	            <td style="color: #003366;" colspan="4">
	            <?php
                while($gr = $res_gruppi->fetch_assoc()){
                    $checked = "";
                    if(isset($_GET['id']) && $_GET['id'] != 0){
                        if(in_array($gr['gid'], $array_gruppi))
                        //if($user['gruppi']&$gr['codice'])
                            $checked = "checked";
                    }
                ?>
                <input class="form_input" type="checkbox" style="margin: auto" value="<?php print $gr['gid'] ?>" name="gruppi[]" <?php print $checked ?>>&nbsp;&nbsp;<?php print $gr['nome'] ?>&nbsp;&nbsp;
                <?php } ?>
	            </td>
	        </tr>
	        <tr class="popup_row">
	            <td colspan="4"></td>
	        </tr>
	    </table>
	    </fieldset>
	    <div style="width: 590px; text-align: right; margin-top: 30px">
	    	<a href="#" onclick="go(<?php if(isset($_GET['id']) && $_GET['id'] != 0) print("3, ".$_REQUEST['id'].", ".$_REQUEST['tipo']); else print("1, 0, ".$_REQUEST['tipo']); ?>, <?php print $_REQUEST['tipo'] ?>)" class="nav_link_first">Registra</a>|
	    	
	    	<?php if(isset($_GET['id']) && $_GET['id'] != 0){
	        ?>
	        <a href="#" style="" onclick="go(2, <?php print $_REQUEST['id'] ?>, <?php print $_REQUEST['tipo'] ?>)" class="nav_link">Cancella il documento</a>|
	        <?php
	        }
	        ?>
	        <a href="#" onclick="parent.win.close()" class="nav_link_last">Chiudi</a>
	        <input type="hidden" name="action" id="action" />
		    <input type="hidden" name="_i" id="_i" />
		    <input type="hidden" name="tipo" value="<?php print $_REQUEST['tipo'] ?>" />
		    <input type="hidden" name="server_file" value="" id="server_file" />
		    <input type="hidden" name="oldfile" value="<?php if(isset($doc)) print $doc['file'] ?>"/>
	    </div>
    </div>
    </form>
</body>
</html>